<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>oscP5 : : OscP5 : : plug ( )</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
document.getElementsByTagName('html')[0].className = 'isjs';
function toggle(dt) 
{ 
  var display, dd=dt; 
  /* get dd */ 
  do{ dd = dd.nextSibling } while(dd.tagName!='DD'); 
  toOpen =!dd.style.display; 
  dd.style.display = toOpen? 'block':'' 
  dt.getElementsByTagName('span')[0].innerHTML 
    = toOpen? '-':'+' ; 
} 
</script>
</head>
<body> 
<div id="container">
	<div id="member">
		<dl><dt class="key">name</dt><dd class="value">plug ( )</dd></dl>
		<dl><dt class="key">description</dt><dd class="value">&nbsp;</dd></dl>
		<dl><dt class="key">Syntax</dt><dd class="value"><pre>plug(theObject, theMethodName, theAddrPattern, theTypeTag);
plug(theObject, theMethodName, theAddrPattern);
</pre></dd></dl>
		<div class="toggleList">
			<dl><dt onclick="toggle(this)"><span>+</span>Examples</dt>
			<dd><pre>import oscP5.*;

/**
 * example of using the plug service with oscP5.
 */

OscP5 oscP5;

// a NetAddress contains the ip address and port number of a remote location in the network.
NetAddress myRemoteLocation;

void setup() {
  size(400,400);
  framerate(25);
  // create a new instance of oscP5 using a multicast socket.
  oscP5 = new OscP5(this,12000);
  
  // create a new NetAddress. a NetAddress is used when sending osc messages
  // with the oscP5.send method.
  myRemoteLocation = new NetAddress("127.0.0.1",12001);
  
  // osc messages with a specific address pattern can automatically be
  // foorwarded to a specific method of an object. in this example 
  // a message with address pattern /test will be forwarded to a method
  // test(). below the method test takes 2 arguments - 2 ints. therefore each
  // message with address pattern /test and typetag ii will be forwarded to
  // the method test(int theA, int theB)
  oscP5.plug(this,"test","/test");
}


public void test(int theA, int theB) {
  println("### plug event method. received a message. 2 int values : "+theA+", "+theB);  
}


void draw() {
  background(0);
}


void mousePressed() {
  // create a new OscMessage with an address pattern, in this case /test.
  OscMessage myOscMessage = new OscMessage("/test");
  // add a value (an integer) to the OscMessage
  myOscMessage.add(100);
  // send the OscMessage to the multicast group.
  oscP5.send(myOscMessage, myRemoteLocation);
}


// incoming osc message are forwarded to the oscEvent method.
void oscEvent(OscMessage theOscMessage) {
  // get and print the address pattern and the typetag of the received OscMessage
  println("### received an osc message with addrpattern "+
		theOscMessage.addrpattern()+" and typetag "+theOscMessage.typetag());
}
</pre></dd>
			</dl>
		</div>
   <dl>
   <dt class="key">parameters</dt><dd class="value"><span class="key">theObject</span><span class="value">Object</span></dd>
	<dd class="value"><span class="key">theMethodName</span><span class="value">String</span></dd>
	<dd class="value"><span class="key">theAddrPattern</span><span class="value">String</span></dd>
	<dd class="value"><span class="key">theTypeTag</span><span class="value">String</span></dd>
	</dl>
	<dl><dt class="key">Returns</dt><dd class="value">None</dd></dl>
	<dl><dt class="key">Usage</dt><dd class="value">Web & Application</dd></dl>
	<dl><dt class="key">Related</dt><dd class="value">&nbsp;</dd></dl>
	</div>
</div>
</body>
</html>